/** Title screen, very basic right now until I can think up something cool for
 * it.
 *@param buffer The ScreenBuffer to render to.
 */
function TitleMode(buffer)
{
	this.buffer = buffer;
	this.menuOptions =
	[
		"New Game",
		"About"
	];
	if(dhack.isSaveAvailable())
		this.menuOptions.unshift("Continue Game");
}
TitleMode.prototype =
{
	/** Handle an input action.
	 *@param action The action to handle.
	 */
	handleAction: function(action)
	{
		switch(action)
		{
			case "use":
				dhack.addModeHandler(
					new MenuListMode(
						this.buffer,
						15,
						null,
						this.menuOptions,
						this.menuCallback,
						this,
						false,
						true
					)
				);
				break;
			default: return false; break;
		}
		return true;
	},
	/** Callback for the menu.
	 *@param option The option selected.
	 *@param source The MenuListHandler that called the callback.
	 */
	menuCallback: function(option, source)
	{
		switch(option)
		{
			case "Continue Game":
				dhack.loadGame();
				break;
			case "New Game":
				if(dhack.isSaveAvailable())
				{
					dhack.addModeHandler(
						new MenuListMode(
							this.buffer,
							30,
							"Starting a new game will delete your previous game save. Do you wish to start a new game?",
							["No", "Yes"],
							this.newGameConfirmCallback,
							this,
							false,
							false
						)
					);
				}
				else
				{
					dhack.newGame();
				}
				break;
			case "About":
				dhack.textBox("About");
				break;
			default:
				source.close();
				break;
		}
	},
	/** Callback for the new game confirmation menu.
	 *@param option The option selected.
	 *@param source The MenuListHandler that called the callback.
	 */
	newGameConfirmCallback: function(option, source)
	{
		if(option == "Yes")
			dhack.newGame();
	},
	/** Render the title screen.
	 */
	render: function()
	{
		this.buffer.clear(" ", null, Color.black);
		this.buffer.blitStringCentered(0, 2, "%f0" + dhack.title + " Version " + dhack.version, this.buffer.width);
		this.buffer.blitStringCentered(0, 3, "%f0by", this.buffer.width);
		this.buffer.blitStringCentered(0, 4, "%f0Norman B. Lancaster (QBRADQ)", this.buffer.width);
		this.buffer.blitStringCentered(0, Math.floor(this.buffer.height / 2), "%f0Press %e0Enter%f0 to Start", this.buffer.width);
	}
};
